package com.lcz.enums;

import com.baomidou.mybatisplus.annotation.DbType;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * @author lcz
 * @desc 数据库id枚举/数据库驱动对应的 databaseId
 * @mail lcz_0130@163.com
 * @date 2024/03/04
 */

@AllArgsConstructor
@Getter
public enum DatabaseIdEnums {
    MYSQL("MySQL", "mysql", "com.mysql.jdbc.Driver", DbType.MYSQL),
    KINGBASEESV8("KingbaseES", "kingbaseesv8", "com.kingbase8.Driver", DbType.KINGBASE_ES),
    POSTGRESQL("POSTGRESQL", "postgresql", "org.postgresql.Driver", DbType.POSTGRE_SQL),
    ORACLE("Oracle", "oracle", "oracle.jdbc.driver.OracleDriver", DbType.ORACLE),
    SQL_SERVER("SQL Server", "sqlserver", "com.microsoft.sqlserver.jdbc.SQLServerDriver", DbType.SQL_SERVER),
    DM("DM DBMS", "dm", "dm.jdbc.driver.DmDriver", DbType.DM);

    /**
     * 数据库名
     */
    private String name;
    /**
     * 数据库名 别名
     */
    private String nameAlias;
    /**
     * 数据库名 别名
     */
    private String driver;
    /**
     * 分页插件名
     */
    private DbType dbType;

    /**
     * 通过数据名获取对应的分页插件
     */
    public static DbType getDbTypeByDriver(String driver) {
        for (DatabaseIdEnums databaseIdEnum : DatabaseIdEnums.values()) {
            if (Objects.equals(databaseIdEnum.getDriver(), driver)) {
                return databaseIdEnum.dbType;
            }
        }
        return null;
    }
}
